<?php


namespace App\Api\Controllers;


use App\Api\Manages\CommonController;
use App\Api\Repositories\CommentRepositorie;
use App\Api\Services\JsonService;
use Illuminate\Http\Request;

class CommentController extends CommonController
{
    //用户评论
    public function comment(Request $request)
    {
        $validat = $request->validate([
            'uid' => ['required'],
            'again_content' => ['required'],
            'goods_id' => ['required'],
            'nickname' => ['required'],
            'explain_type' => ['required'],
            'pid' => ['required'],
        ]);
        $comment = CommentRepositorie::addComment($validat);
        if($comment){
            return JsonService::success('评论成功','',config('code.HTTP_OK'));
        }else{
            return JsonService::fail('评论失败','',config('code.HTTP_FAIL'));
        }
    }
    
    //获取用户评论
    public function getComment(Request $request)
    {
        $validat = $request->validate([
            'goods_id' => ['required']
        ]);
        $comment = CommentRepositorie::getAllComment((int)$validat['goods_id']);
        if($comment){
            return JsonService::success('查询成功',$comment,config('code.HTTP_OK'));
        }else{
            return JsonService::fail('查询失败','',config('code.HTTP_OK'));
        }
    }
}